﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_Modes;
using Zor_IDAL;
using Zor_Tools;
using System.Data;
using Dapper;
namespace Zor_DAL
{
    public class Zor_Review_DAL<T> where T : class
    {
        /// <summary>
        /// 推送提交至评定
        /// create zhl by 17.3.31
        /// </summary>
        /// <param name="review">评议对象</param>
        /// <returns>2--当前评议已推送-1操作失败1--操作成功的标识</returns>
        public static int Review(Zor_Review review)
        {
            var param = new DynamicParameters();
            param.Add("@Review_Id", review.Review_Id);
            param.Add("@Acceptance_Id", review.Acceptance_Id);
            param.Add("@Review_TotalTax", review.Review_TotalTax);
            param.Add("@Review_Rent", review.Review_Rent);
            param.Add("@Review_PersonalTax", review.Review_PersonalTax);
            param.Add("@Review_PropertyTax", review.Review_PropertyTax);
            param.Add("@Review_Tax", review.Review_Tax);
            param.Add("@Review_Comment", review.Review_Comment);
            param.Add("@Review_State", review.Review_State);         
            param.Add("@User_Id", RequestSession.GetSessionUser().User_Id);
            param.Add("@CreateTime", TimeHelper.ToTimeStamp(DateTime.Now));
            param.Add("@narid", 0, DbType.Int32, ParameterDirection.ReturnValue);
            using (IDbConnection conn = DapperConn.OpenSqlConnection())
            {
                var Answer = conn.Execute("Pro_Review", param, null, null, CommandType.StoredProcedure);
                return param.Get<int>("@narid");
            }
        }

        /// <summary>
        /// 退回至受理单
        /// create zhl by 17.3.31
        ///受理状态(0保存,1提交2被退回、3已评议4已评定5、已审核、6已缴税、7、已开票8、已消号)
        ///--评议状态(0保存1,提交2被退回3退回至受理单)  
        /// </summary>
        /// <param name="aptid">受理单id</param>
        /// <param name="review">评议对象</param>      
        /// <returns></returns>
        public static BaseAnswer ReturnAcceptance(Zor_Review review)
        {

            List<string> lstsql = new List<string>();

            //更新受理单状态
            lstsql.Add(string.Format("update [Zor_Acceptance] set Acceptance_State=2 where Acceptance_Id=" + review .Acceptance_Id+ ""));
            //更新评议状态
            lstsql.Add(string.Format("update [Zor_Review] set Review_State=3 where Acceptance_Id=" + review.Acceptance_Id + ""));           
            //退回记录表增加数据
            lstsql.Add(string.Format("insert into Zor_ReturnRecord values(" + review.Review_Id + ",'" + review.Review_Comment + "'," + RequestSession.GetSessionUser().User_Id + "," + TimeHelper.ToTimeStamp(DateTime.Now) + ",1)"));     
            BaseAnswer bar = DapperTransaction.DoTransaction(lstsql);
            return bar;
        }
    }
}
